from rest_framework.response import Response
from rest_framework.decorators import action
from .models import *

class Menus():
    def __init(self,user):
        self.user = user

		# 获取角色
    def get_role(self):
        roleuser = RolesUser.objects.filter(user=self.user).first()
        roles = roleuser.role.all()
        return roles
    		# 去二级菜单重
    def get_twomenus(self):
        roles = get_role()
        menus_tem = set([])
        for role in roles:
            for menus in role.roles.all():
                menus_tem.add(menus)
        return menus_tem

    def get_onemenus(self):
        twoemenus = get_twomenus()
		# 一级菜单去重
        onemenu = set([])
        for tem in twoemenus:
            onemenu.add(tem.menu)
        return onemenu
        
    def tranformjson(self):
        return None